/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exatrez.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Mansur
 */
@Entity
@Table(name = "ship_visit3")
@NamedQueries({
    @NamedQuery(name = "ShipVisit3.findAll", query = "SELECT s FROM ShipVisit3 s")})
public class ShipVisit3 implements Serializable{
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ship_visit3_id")
    private Integer shipVisit3Id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id")
    private User user;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "department_crn_id")
    private Department departmentCurrent;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "vessel_id")
    private Vessel vessel;
    
    @Column(name = "date_visit")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateVisit;
    
    @Column(name = "location")
    private String location;
    
    @Column(name = "delete_flag")
    private String deleted;
    
    @Column(name = "status_flag")
    private String status;  // K=KIV, A=Approved, R=Rejected
    
    @Column(name = "wflow_curr_flag")
    private String workflow;  // T=True, F=False
    
    @Column(name = "reject_note")
    private String rejectNote;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "verifier_id")
    private User verifierId;
    
    @OneToMany (mappedBy = "shipVisit3" , fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ShipVisit3Sub> listShipVisitSub;
    
    @OneToMany (mappedBy = "shipVisit3" , fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ShipVisit3File> listFile;
    
    @OneToMany (mappedBy = "shipVisit3" , fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private List<ShipVisit3History> listHistory;
    
    @Embedded
    private InfoAudit infoAudit;
    
    public ShipVisit3(){
        
    }

    public Integer getShipVisit3Id() {
        return shipVisit3Id;
    }

    public void setShipVisit3Id(Integer shipVisit3Id) {
        this.shipVisit3Id = shipVisit3Id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Department getDepartmentCurrent() {
        return departmentCurrent;
    }

    public void setDepartmentCurrent(Department departmentCurrent) {
        this.departmentCurrent = departmentCurrent;
    }

    public Vessel getVessel() {
        return vessel;
    }

    public void setVessel(Vessel vessel) {
        this.vessel = vessel;
    }

    public Date getDateVisit() {
        return dateVisit;
    }

    public void setDateVisit(Date dateVisit) {
        this.dateVisit = dateVisit;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getDeleted() {
        return deleted;
    }

    public void setDeleted(String deleted) {
        this.deleted = deleted;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getWorkflow() {
        return workflow;
    }

    public void setWorkflow(String workflow) {
        this.workflow = workflow;
    }

    public String getRejectNote() {
        return rejectNote;
    }

    public void setRejectNote(String rejectNote) {
        this.rejectNote = rejectNote;
    }

    public User getVerifierId() {
        return verifierId;
    }

    public void setVerifierId(User verifierId) {
        this.verifierId = verifierId;
    }

    public List<ShipVisit3Sub> getListShipVisitSub() {
        return listShipVisitSub;
    }

    public void setListShipVisitSub(List<ShipVisit3Sub> listShipVisitSub) {
        this.listShipVisitSub = listShipVisitSub;
    }

    public List<ShipVisit3File> getListFile() {
        List<ShipVisit3File> l = new ArrayList<ShipVisit3File>();
        for (ShipVisit3File f : listFile) {
            if(f.getDeleted().equals("N"))
                l.add(f);
        }
        listFile.clear();
        listFile = l;
        return listFile;
    }

    public void setListFile(List<ShipVisit3File> listFile) {        
        this.listFile = listFile;
    }

    public List<ShipVisit3History> getListHistory() {
        return listHistory;
    }

    public void setListHistory(List<ShipVisit3History> listHistory) {
        this.listHistory = listHistory;
    }

    public InfoAudit getInfoAudit() {
        return infoAudit;
    }

    public void setInfoAudit(InfoAudit infoAudit) {
        this.infoAudit = infoAudit;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (shipVisit3Id != null ? shipVisit3Id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ShipVisit3)) {
            return false;
        }
        ShipVisit3 other = (ShipVisit3) object;
        if ((this.shipVisit3Id == null && other.shipVisit3Id != null) || (this.shipVisit3Id != null && !this.shipVisit3Id.equals(other.shipVisit3Id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "exatrez.model.ShipVisit3[ shipVisit3Id=" + shipVisit3Id + " ]";
    }
}
